﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Desaware.MachineLicense40;

namespace FMS.Formulation.Licensing.Engine
{

    internal class ClientSystemMatch : ISystemMatch
    {
        public bool CheckDemoMatch(SystemIdentifierInfo[] Identifiers, SystemIdentifierInfo[] ExistingEntries)
        {
            int num = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;
            int num5 = 0;
            int num6 = 0;
            bool flag = false;
            WMINetworkAdapterInfo wMINetworkAdapterInfo = new WMINetworkAdapterInfo();
            string text = wMINetworkAdapterInfo.Read();
            if (text.Trim().Length > 0)
            {
                flag = true;
            }
            foreach (SystemIdentifierInfo systemIdentifierInfo in Identifiers)
            {
                SystemIdentifierInfo[] array;
                if (systemIdentifierInfo.Name.Trim().Equals("BIOS", StringComparison.InvariantCultureIgnoreCase))
                {
                    array = ExistingEntries;
                    foreach (SystemIdentifierInfo systemIdentifierInfo2 in array)
                    {
                        if (systemIdentifierInfo.Name.Trim().Equals(systemIdentifierInfo2.Name.Trim(), StringComparison.InvariantCultureIgnoreCase) && systemIdentifierInfo.Value.Equals(systemIdentifierInfo2.Value, StringComparison.InvariantCultureIgnoreCase))
                        {
                            num3++;
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    num4++;
                    num6++;
                }
                else
                {
                    if (systemIdentifierInfo.Name.Trim().Equals("MACHINE", StringComparison.InvariantCultureIgnoreCase))
                    {
                        array = ExistingEntries;
                        foreach (SystemIdentifierInfo systemIdentifierInfo2 in array)
                        {
                            if (systemIdentifierInfo.Name.Trim().Equals(systemIdentifierInfo2.Name.Trim(), StringComparison.InvariantCultureIgnoreCase) && systemIdentifierInfo.Value.Equals(systemIdentifierInfo2.Value, StringComparison.InvariantCultureIgnoreCase))
                            {
                                num4++;
                                break;
                            }
                        }
                    }
                    if (systemIdentifierInfo.Name.Trim().Equals("NETWORK", StringComparison.InvariantCultureIgnoreCase))
                    {
                        array = ExistingEntries;
                        foreach (SystemIdentifierInfo systemIdentifierInfo2 in array)
                        {
                            if (systemIdentifierInfo.Name.Trim().Equals(systemIdentifierInfo2.Name.Trim(), StringComparison.InvariantCultureIgnoreCase) && systemIdentifierInfo.Value.Equals(systemIdentifierInfo2.Value, StringComparison.InvariantCultureIgnoreCase))
                            {
                                num6++;
                                break;
                            }
                        }
                    }
                }
                if (!systemIdentifierInfo.Name.Trim().Equals("PROCESSOR", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                array = ExistingEntries;
                foreach (SystemIdentifierInfo systemIdentifierInfo2 in array)
                {
                    if (systemIdentifierInfo.Name.Trim().Equals(systemIdentifierInfo2.Name.Trim(), StringComparison.InvariantCultureIgnoreCase) && systemIdentifierInfo.Value.Equals(systemIdentifierInfo2.Value, StringComparison.InvariantCultureIgnoreCase))
                    {
                        num5++;
                        break;
                    }
                }
            }
            num2 = num3 + num4 + num5 + num6;
            num = Identifiers.Length;
            int num7 = num2 * 100 / num;
            if (num7 >= 80)
            {
                return true;
            }
            return false;
        }

        public bool CheckInstallationMatch(SystemIdentifierInfo[] Identifiers, SystemIdentifierInfo[] ExistingEntries)
        {
            return CheckDemoMatch(Identifiers, ExistingEntries);
        }
    }

}
